import { Controller, Get, Param, Query, Post, Body} from '@nestjs/common';
import { TUserBasicService } from './user-basic.service';
import { TUserBasic } from '../../entities/user-basic.entity';
interface UserInfo {
  userId: number;
}
interface ApiResponse<T> {
  data: T,
  status:  'success' | 'error' | 'warning' | 'info';
  msg: string
}
@Controller('users')
export class TUserBasicController {
  constructor(private readonly userService: TUserBasicService) {}
  /**
   * 获取用户信息
   */
  @Post('/getUserInfo')
  async getUserInfo(
    @Body() body: UserInfo,
  ): Promise<ApiResponse<TUserBasic[]>> {
    if (!body?.userId) {
      return {
        data: null,
        status: 'error',
        msg: '用户ID不能为空',
      };
    }
    try {
      const userInfo = await this.userService.getUserInfo(body.userId);
      return {
        data: userInfo,
        status: 'success',
        msg: '操作成功',
      };
    } catch (error) {
      return {
        data: null,
        status: 'error',
        msg: '获取用户信息失败',
      };
    }
  }

  /**
   * 查询所有用户
   */
  // @Get(':id') // url/id 这种格式
  // async getAllUsers(@Param('id') id: string): Promise<TUserBasic[]> {
  //   console.log(id, "get参数")
  //   return await this.userService.findAll();
  // }

  /**
   * 查询所有用户（按创建时间倒序）
   */
  @Get('ordered')
  async getAllUsersOrdered(
    @Query('page') page: number,
    @Query('limit') limit: number,
  ): Promise<TUserBasic[]> {
    console.log(page, 'page参数');
    console.log(limit, 'limit参数');
    return await this.userService.findAllOrderByCreateTime();
  }
  
}